
import {Iaction} from '../../utils/interface';

const initialState={
    categoryList:[],
    currentCategory:{}
}
const actions:{[key:string]:Function}={
    'INIT_CATEGORY':(state:any,action:Iaction)=>{
        state = Object.assign(state,action.payload)
    },
    'SET_TAB':(state:any,action:Iaction)=>{
        state = Object.assign(state,{currentCategory:action.payload.currentCategory})
    },
    'SET_DETAIL':(state:any,action:Iaction)=>{
        state = Object.assign(state,{...action.payload})
    },
    'SET_DETAILLIST':(state:any,action:Iaction)=>{
        state = Object.assign(state,{...action.payload})
    },
}
const reducer = (state=initialState,action:Iaction)=>{
    const newState = JSON.parse(JSON.stringify(state));
    actions[action.type] && actions[action.type](newState,action);
    return newState
}

export default reducer